package com.example.service;

import com.example.mapper.OrderMapper;
import com.example.model.OrderInfo;
import com.example.model.OrderInfoP;
import com.example.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    public OrderInfo selectOrderById(Integer orderId) {
        OrderInfo orderInfo = orderMapper.selectOrderById(orderId);
        return orderInfo;
    }

    public OrderInfoP selectOrderByIdP(Integer orderId) {
        OrderInfo orderInfo = orderMapper.selectOrderById(orderId);
        String url = "http://127.0.0.1:8081/product/"+
                orderInfo.getProductId();
        ProductInfo productInfo = restTemplate.getForObject(url,
                ProductInfo.class);
        OrderInfoP orderInfoP = new OrderInfoP(orderInfo);
        orderInfoP.setProductInfo(productInfo);
        return orderInfoP;
    }
}
